<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8">
<!-- inputs-linux-device.qdoc -->
  <title>Inputs on an Embedded Linux Device | Qt 5.14</title>
  <link rel="stylesheet" type="text/css" href="style/offline-simple.css" />
  <script type="text/javascript">
    document.getElementsByTagName("link").item(0).setAttribute("href", "style/offline.css");
    // loading style sheet breaks anchors that were jumped to before
    // so force jumping to anchor again
    setTimeout(function() {
        var anchor = location.hash;
        // need to jump to different anchor first (e.g. none)
        location.hash = "#";
        setTimeout(function() {
            location.hash = anchor;
        }, 0);
    }, 0);
  </script>
</head>
<body>
<div class="header" id="qtdocheader">
  <div class="main">
    <div class="main-rounded">
      <div class="navigationbar">
        <table><tr>
<td ><a href="index.html">Qt 5.14</a></td><td >Inputs on an Embedded Linux Device</td></tr></table><table class="buildversion"><tr>
<td id="buildversion" width="100%" align="right">Qt 5.14.2 Reference Documentation</td>
        </tr></table>
      </div>
    </div>
<div class="content">
<div class="line">
<div class="content mainContent">
<div class="sidebar">
<div class="toc">
<h3><a name="toc">Contents</a></h3>
<ul>
<li class="level2"><a href="#use-libinput">Use libinput</a></li>
<li class="level2"><a href="#input-on-eglfs-and-linuxfb-without-libinput">Input on eglfs and linuxfb without libinput</a></li>
<li class="level2"><a href="#mouse">Mouse</a></li>
<li class="level2"><a href="#keyboard">Keyboard</a></li>
<li class="level2"><a href="#touch">Touch</a></li>
<li class="level2"><a href="#pen-based-tablets">Pen-based Tablets</a></li>
<li class="level2"><a href="#debug-input-devices">Debug Input Devices</a></li>
<li class="level2"><a href="#use-custom-mouse-cursor-images">Use Custom Mouse Cursor Images</a></li>
</ul>
</div>
<div class="sidebar-content" id="sidebar-content"></div></div>
<h1 class="title">Inputs on an Embedded Linux Device</h1>
<span class="subtitle"></span>
<!-- $$$inputs-linux-device.html-description -->
<div class="descr"> <a name="details"></a>
<p>On your Embedded Linux device, when there's no windowing system present, the mouse, keyboard, and touch input are read directly via <code>evdev</code> or using helper libraries such as <code>libinput</code> or <code>tslib</code>. However, this behavior requires that device nodes <code>/dev/input/event*</code> are readable by the user. <code>eglfs</code> and <code>linuxfb</code> have all the input handling code compiled-in.</p>
<a name="use-libinput"></a>
<h3 id="use-libinput">Use libinput</h3>
<p><a href="https://www.freedesktop.org/wiki/Software/libinput">libinput</a> is a library to handle input devices that offers an alternative to the Qt's own <code>evdev</code> input support. To enable using <code>libinput</code>, when you configure and build Qt, make sure that the development files for <code>libudev</code> and <code>libinput</code> are available. If you require keyboard support, then <code>xkbcommon</code> is also necessary. With <code>eglfs</code> and <code>linuxfb</code>, no further actions are necessary as these plugins use <code>libinput</code> by default. If <code>libinput</code> support is not available or the <code>QT_QPA_EGLFS_NO_LIBINPUT</code> environment variable is set, then Qt's own <code>evdev</code> handlers are used instead.</p>
<a name="input-on-eglfs-and-linuxfb-without-libinput"></a>
<h3 id="input-on-eglfs-and-linuxfb-without-libinput">Input on eglfs and linuxfb without libinput</h3>
<p>Parameters like the device node name can be set in the <code>QT_QPA_EVDEV_MOUSE_PARAMETERS</code>, <code>QT_QPA_EVDEV_KEYBOARD_PARAMETERS</code> and <code>QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS</code> environment variables; separate your entries with colons. These parameters are an alternative to passing the settings in the <code>-plugin</code> command-line argument, and with some backends they are essential. But <code>eglfs</code> and <code>linuxfb</code> use built-in input handlers so there's no separate <code>-plugin</code> argument in use.</p>
<p>Additionally, the built-in input handlers can be disabled by setting <code>QT_QPA_EGLFS_DISABLE_INPUT</code> (for <code>eglfs</code>) or <code>QT_QPA_FB_DISABLE_INPUT</code> (for <code>linuxfb</code>) to <code>1</code>.</p>
<a name="mouse"></a>
<h3 id="mouse">Mouse</h3>
<p>The mouse cursor shows up whenever <code>QT_QPA_EGLFS_HIDECURSOR</code> (for <code>eglfs</code>) or <code>QT_QPA_FB_HIDECURSOR</code> (for <code>linuxfb</code>) isn't set and Qt's libudev-based device discovery reports that at least one mouse is available. When <code>libudev</code> support is not present, the mouse cursor is always displayed; unless it's explicitly disabled via the environment variable.</p>
<p>If Qt was configured with <code>libudev</code> support, connecting or disconnecting an input device while the application is running (hot plugging) is supported. Then <code>libudev</code> development headers are present in the sysroot at configure time.</p>
<p>The <code>evdev</code> mouse handler supports the following extra parameters:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Parameter</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><code>/dev/input/..&#x2e;</code></td><td >Specifies the name of the input device. If unspecified, Qt looks for a suitable device either via <code>libudev</code> or by traversing the available nodes.</td></tr>
<tr valign="top" class="even"><td ><code>nocompress</code></td><td >By default, input events that don't lead to changing the position compared to the last Qt mouse event are compressed. A new Qt mouse event is sent only after a change in the position or button state. To disable this behavior, set the <code>nocompress</code> parameter.</td></tr>
<tr valign="top" class="odd"><td ><code>dejitter</code></td><td >Specifies a jitter limit; disabled by default.</td></tr>
<tr valign="top" class="even"><td ><code>grab</code></td><td >When set to <code>1</code>, Qt grabs the device for exclusive use.</td></tr>
<tr valign="top" class="odd"><td ><code>abs</code></td><td >Some touchscreens report absolute coordinates and can't be differentiated from touchpads. In this case, pass <code>abs</code> to indicate that the device is using absolute events.</td></tr>
</table></div>
<a name="keyboard"></a>
<h3 id="keyboard">Keyboard</h3>
<p>The <code>evdev</code> keyboard handler supports the following extra parameters:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Parameter</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><code>/dev/input/..&#x2e;</code></td><td >Specifies the name of the input device. If unspecified, Qt looks for a suitable device either via <code>libudev</code> or by traversing the available nodes.</td></tr>
<tr valign="top" class="even"><td ><code>grab</code></td><td >Enables grabbing the input device.</td></tr>
<tr valign="top" class="odd"><td ><code>keymap</code></td><td >Specifies the name of a custom keyboard map file.</td></tr>
<tr valign="top" class="even"><td ><code>enable-compose</code></td><td >Enables compositing.</td></tr>
<tr valign="top" class="odd"><td ><code>repeat-delay</code></td><td >Sets a custom key repeat delay.</td></tr>
<tr valign="top" class="even"><td ><code>repeat-rate</code></td><td >Sets a custom key repeat rate.</td></tr>
</table></div>
<p>On Embedded Linux systems that don't have their terminal sessions disabled, the behavior on a key press can be confusing, as the input event is processed by the Qt application and the tty. To overcome this, the following options are available:</p>
<ul>
<li>On application startup, <code>EGLFS</code> and <code>LinuxFB</code> attempt to disable the terminal keyboard by setting the tty's keyboard mode to <code>K_OFF</code>. This prevents keystrokes from being sent to the terminal. If the standard behavior is required, set the <code>QT_QPA_ENABLE_TERMINAL_KEYBOARD</code> environment variable to <code>1</code>. Note that this works only when the application is launched from a remote console, via <code>ssh</code> for example, and the terminal keyboard input remains enabled.</li>
<li>An alternative approach is to use the <code>evdev</code> keyboard handler's <code>grab</code> parameter by passing <code>grab=1</code> in <code>QT_QPA_EVDEV_KEYBOARD_PARAMETERS</code>. This results in trying to get a grab on the input device. If the <code>grab</code> is successful, no other components in the system receive events from it, as long as the Qt application is running. This approach is more suitable for applications that start remotely as it doesn't need access to the tty device.</li>
<li>Finally, for many specialized Embedded Linux images it doesn't make sense to have the standard terminal sessions enabled in the first place. For more details on how to disable these terminal sessions, refer to your build environment's Documentation. For example, when generating images using the <a href="https://www.yoctoproject.org">Yocto Project</a>, unsetting <code>SYSVINIT_ENABLED_GETTYS</code> results in having no <code>getty</code> process running. This means, there's no input on any of the virtual terminals.</li>
</ul>
<p>If the default built-in keymap is not sufficient, you can specify a different one either via the <code>keymap</code> parameter or via the eglfs-specific <a href="../qtplatformheaders/qeglfsfunctions.html#loadKeymap">loadKeymap()</a> function. The latter allows for switching the keymap at runtime. However, this behavior requires using eglfs' built-in keyboard handler; it is not supported when the keyboard handler is loaded via the <code>-plugin</code> command-line parameter.</p>
<p><b>Note: </b>Special system key combinations, such as console switching (<b>Ctrl+Alt+Fx</b>) or zap (<b>Ctrl+Alt+Backspace</b>) are not currently supported and are ignored.</p><p>To generate a custom keymap, use the <code>kmap2qmap</code> utility, that can be found in the <code>qttools</code> module. The source files have to be in standard Linux <code>kmap</code> format, which is understood by the kernel's <code>loadkeys</code> command. <code>qmap</code> files can be generated in one of the following ways:</p>
<ul>
<li>The <a href="http://lct.sourceforge.net/">Linux Console Tools (LCT)</a> project.</li>
<li><a href="https://www.x.org/">X.org</a> X11 keymaps can be converted to the <code>kmap</code> format with the <code>ckbcomp</code> utility.</li>
<li>As <code>kmap</code> files are plain-text files, they can also be hand crafted.</li>
</ul>
<p><code>kmap2qmap</code> is a command line program, that needs at least 2 files as parameters. The last parameter is the generated <code>.qmap</code> file, while all the others are parsed as input <code>.kmap</code> files. For example:</p>
<pre class="cpp plain">

  kmap2qmap i386/qwertz/de-latin1-nodeadkeys.kmap include/compose.latin1.inc de-latin1-nodeadkeys.qmap

</pre>
<p><b>Note: </b><code>kmap2qmap</code> doesn't support all the (pseudo) symbols that the Linux kernel supports. Consequently, when you convert a standard keymap, there'll be a number of warnings regarding <code>Show_Registers</code>, <code>Hex_A</code>, and so on; these messages can be ignored.</p><a name="touch"></a>
<h3 id="touch">Touch</h3>
<p>While it's not necessary for modern touch screens, some resistive, single-touch touch screens may require that you fallback to using <code>tslib</code> instead of relying on the Linux multi-touch protocol and the event devices.</p>
<p>To enable <code>tslib</code> support, set the <code>QT_QPA_EGLFS_TSLIB</code> (for <code>eglfs</code>) or <code>QT_QPA_FB_TSLIB</code> (for <code>linuxfb</code>) environment variable to 1. To change the device, set the <code>TSLIB_TSDEVICE</code> environment variable or pass the device name on the command-line. Note that the <code>tslib</code> input handler generates mouse events and supports single touch only, as opposed to <code>evdevtouch</code> which generates true multi-touch <a href="../qtgui/qtouchevent.html">QTouchEvent</a> events too.</p>
<p>The <code>evdev</code> touch handler supports the following extra parameters:</p>
<div class="table"><table class="generic">
 <thead><tr class="qt-style"><th >Parameter</th><th >Description</th></tr></thead>
<tr valign="top" class="odd"><td ><code>/dev/input/..&#x2e;</code></td><td >Specifies the name of the input device. If unspecified, Qt looks for a suitable device either via <code>libudev</code> or by traversing the available nodes.</td></tr>
<tr valign="top" class="even"><td ><code>rotate</code></td><td >On some touch screens the coordinates must be rotated by setting <code>rotate</code> to 90, 180, or 270.</td></tr>
<tr valign="top" class="odd"><td ><code>invertx</code> and <code>inverty</code></td><td >Specifies the parameters to invert the X or Y coordinates in the input events.</td></tr>
</table></div>
<p>For example, if you pass the following values to <code>QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS</code> before launching applications, you'd have an explicitly specified touch device with the coordinates flipped. This is useful when the orientation of the actual screen and the touch screen don't match.</p>
<pre class="cpp plain">

  export QT_QPA_EVDEV_TOUCHSCREEN_PARAMETERS=/dev/input/event5:rotate=180

</pre>
<a name="pen-based-tablets"></a>
<h3 id="pen-based-tablets">Pen-based Tablets</h3>
<p>The <code>evdevtablet</code> plugin provides basic support for Wacom and similar pen-based tablets. It generates <a href="../qtgui/qtabletevent.html">QTabletEvent</a> events only. To enable it, pass <code>QT_QPA_GENERIC_PLUGINS=evdevtablet</code> in the environment or, alternatively, pass the <code>-plugin evdevtablet</code> argument on the command-line.</p>
<p>The plugin can take a device node parameter, such as <code>QT_QPA_GENERIC_PLUGINS=evdevtablet:/dev/event1</code>, if Qt's automatic device discovery (based either on <code>libudev</code> or traversing <code>/dev/input/event*</code>) isn't functional or is misbehaving.</p>
<a name="debug-input-devices"></a>
<h3 id="debug-input-devices">Debug Input Devices</h3>
<p>It's possible to print some information to the debug output by enabling the <code>qt.qpa.input</code> logging rule, for example by setting the <code>QT_LOGGING_RULES</code> environment variable to <code>qt.qpa.input=true</code>. This is useful for detecting which device is being used, or for troubleshooting device discovery issues.</p>
<a name="use-custom-mouse-cursor-images"></a>
<h3 id="use-custom-mouse-cursor-images">Use Custom Mouse Cursor Images</h3>
<p><code>eglfs</code> comes with its own set of 32x32-sized mouse cursor images. If these are insufficient, you can provide a custom cursor atlas by setting the <code>QT_QPA_EGLFS_CURSOR</code> environment variable to the name of a JSON file. This file can also be embedded into the application via <a href="../qtcore/resources.html">The Qt Resource System</a>.</p>
<p>For example, an embedded cursor atlas with 8 cursor images per row can be specified as follows:</p>
<pre class="cpp plain">

  {
    &quot;image&quot;: &quot;:/cursor-atlas.png&quot;,
    &quot;cursorsPerRow&quot;: 8,
    &quot;hotSpots&quot;: [
        [7, 2],
        [12, 3],
        [12, 12],
        ..&#x2e;
    ]
  }

</pre>
<p>Note that the images are expected to be tightly packed in the atlas; the width and height of the cursors are determined based on the total image size and the <code>cursorsPerRow</code> setting. Atlases must also provide an image for all of the supported cursors.</p>
</div>
<!-- @@@inputs-linux-device.html -->
        </div>
       </div>
   </div>
   </div>
</div>
<div class="footer">
   <p>
   <acronym title="Copyright">&copy;</acronym> 2020 The Qt Company Ltd.
   Documentation contributions included herein are the copyrights of
   their respective owners.<br/>    The documentation provided herein is licensed under the terms of the    <a href="http://www.gnu.org/licenses/fdl.html">GNU Free Documentation    License version 1.3</a> as published by the Free Software Foundation.<br/>    Qt and respective logos are trademarks of The Qt Company Ltd.     in Finland and/or other countries worldwide. All other trademarks are property
   of their respective owners. </p>
</div>
</body>
</html>
